﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Speakup;
using WebLayer;
using System.Diagnostics;
using System.Threading;
using TableTypes;

namespace SpeakupUI
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            Application app = new Application();
            
            /* Window win = new Window();
            win.Height = 800;
            win.Width = 1000;
            win.Title = "boo";
    
            TimeSpan begin = new TimeSpan(8, 0, 0);
            TimeSpan end = new TimeSpan(22, 0, 0);
            TimeSlotDuration workingHours = new TimeSlotDuration(begin, end);

            TimeSheet timeSheet = new TimeSheet(workingHours,new TimeSpan(0,30,0), 12);

            win.Content = timeSheet;

            ClassList classes = null;

            try
            {
                classes = ClassList.Load("classCache.bin");
            }
            catch (Exception )
            {
                //ignore
            }

            if(classes == null)
            {
                LoginToken loginToken = new LoginToken("2448", "6181", "4001");
                classes = ClassList.Fetch(loginToken);
            }

            classes.Save("classCache.bin");
            

            foreach(Class entry in classes)
            {
                if (entry.ClassTime.Date < DateTime.Now.Date ||
                    entry.ClassTime.Date > DateTime.Now.Date + new TimeSpan(11, 0, 0, 0))
                {
                    //skip
                    continue;
                }

                if (entry.ClassId == 0 ||
                    entry.ClassTime.Begin < new TimeSpan(8, 0, 0) ||
                    entry.ClassTime.End > new TimeSpan(22, 0, 0))
                {
                    continue;
                }

                Label name = new Label();
                name.Content = entry.ClassName;

                DockPanel panel = new DockPanel();
                panel.Children.Add(name);
                panel.Background = Brushes.LightGreen;

                if (entry.ClassStatus == ClassStatus.Reserved)
                {
                    panel.Background = Brushes.LightBlue;
                }

                if( entry.ClassStatus == ClassStatus.ReservedWaitList)
                {
                    panel.Background = Brushes.LightYellow;
                }

                if( entry.ClassStatus == ClassStatus.AvailableWaitList)
                {
                    panel.Background = Brushes.LightPink;
                }

                panel.Background = panel.Background.Clone();
                
                TimeSlotDuration slot = new TimeSlotDuration();
                slot.Begin = entry.ClassTime.Begin;
                slot.End   = entry.ClassTime.End;
                
                timeSheet.AddSlotChild(slot,entry.ClassTime.Date, panel);
                
            }*/

          /*  WaitDialog dlg = new WaitDialog();
            dlg.ShowDialog(); */

            
            MainWindow mainWindow = new MainWindow();
            app.ShutdownMode = ShutdownMode.OnMainWindowClose;
            app.Run(mainWindow);
        }

    }
}
